﻿using System;
using System.Drawing;
using RaytracerLib.Layers;
using RaytracerLib.MathLib;
using TomanuExtensions;

namespace RaytracerLib.Postprocessing.LightCorrector
{
    public class ScaleEachPixelToneMapper : ToneMapper
    {
        internal override void Postprocess(Rectangle a_src_rect, ColorArrayFloat a_ar)
        {
            foreach (var p in a_src_rect.EnumPixels())
            {
                ColorFloat c = a_ar.GetColor(p.X, p.Y);
                float m = Math.Max(Math.Max(c.R, c.G), c.B);
                if (m > 1)
                {
                    c = new ColorFloat(c.R / m, c.G / m, c.B / m);
                    a_ar.SetColor(p.X, p.Y, c);
                }
            }
        }

        public override bool RequiredPostprocessingFinalization
        {
            get
            {
                return false;
            }
        }
    }
}